package com.wy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wy.controller.dto.DiagnosisDto;
import com.wy.entity.Diagnosis;
import com.wy.entity.Drug;
import com.wy.entity.PetDrug;
import com.wy.mapper.DiagnosisMapper;
import com.wy.mapper.DrugMapper;
import com.wy.mapper.PetDrugMapper;
import com.wy.service.IDiagnosisService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 王昭贵
 * @since 2023-03-22
 */
@Service
public class DiagnosisServiceImpl extends ServiceImpl<DiagnosisMapper, Diagnosis> implements IDiagnosisService {

    @Resource
    private DiagnosisMapper diagnosisMapper;
    @Resource
    private PetDrugMapper petDrugMapper;
    @Resource
    private DrugMapper drugMapper;
    @Override
    public DiagnosisDto getDiagnosisByIdToReviewTreat(Integer id) {
        DiagnosisDto diagnosisByIdToReviewTreat = diagnosisMapper.getDiagnosisByIdToReviewTreat(id);
        List<PetDrug> petDrugs = petDrugMapper.selectList(new LambdaQueryWrapper<PetDrug>().eq(PetDrug::getDiagnosisId, id));
        List<Integer> collect = petDrugs.stream().map(PetDrug::getDrugId).collect(Collectors.toList());
        List<Drug> petDrugs1 =new ArrayList<>();
        for (Integer integer : collect) {
            petDrugs1.add(drugMapper.selectById(integer));
        }
        diagnosisByIdToReviewTreat.setPetDrugList(petDrugs1);
        return diagnosisByIdToReviewTreat;
    }
}
